package model.entity.stats;

import utilities.*;

public abstract class StatModifier implements Archiveable {
	// Instance Variables
	private String name;
	protected double value;
	
	
	// Constructor
	/**
	 * Default constructor. Initializes empty values
	 */
	public StatModifier() {
		this("", 0.0);
	}
	
	/**
	 * Constructor: Sets name and value
	 * @param n
	 * @param v
	 */
	public StatModifier(String n, double v) {
		this.name = n;
		this.value = v;
	}
	
	
	// Getters
	/**
	 * Returns the name
	 */
	public String getName() {
		return this.name;
	}
	
	/**
	 * This abstract method is for calculating the delta value of the stat
	 * modifier, taking into account the baseValue of the stat
	 * @param baseValue
	 * @return the calculated delta value
	 */
	abstract public double getValue(double baseValue);
	
	
	public Archive save() {
		Archive archive = ArchiveFactory.createArchive();
		
		archive.putAttribute("name", this.name);
		archive.putAttribute("value", Double.toString(this.value));
		
		return archive;
	}
	
	public void load(Archive archive) {
		this.name = archive.getAttribute("name");
		this.value = Double.parseDouble(archive.getAttribute("value"));
	}
	
}

